package net.maxwoods.nimble.script;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Arrays;

public class LDConsole {

    public String hello() {
        return "Hello," + getClass().getName();
    }

    public String cmd() throws Exception {
        ProcessBuilder builder = new ProcessBuilder("D:\\Applications\\dnplayer2\\dnconsole.exe","adb","--name","test1",
                "--command","shell /system/bin/screencap -p /sdcard/1.png");
        builder.redirectErrorStream(true);
        Process process = builder.start();
        InputStream in = process.getInputStream();
        ByteArrayOutputStream bos=new ByteArrayOutputStream();
        byte[] re = new byte[1024];
        while (in.read(re) != -1) {
            bos.write(re);
            Arrays.fill(re,(byte)0);
        }
        in.close();
        if (process.isAlive()) {
            process.waitFor();
        }
        return new String(bos.toByteArray());
    }
}
